<template>
  <div>
    <div :style="{height: toolbarHei +'px'}"></div>
    <nut-navbar title="个人信息" left-text="返回" left-show @click-back="clickLeft"></nut-navbar>
    <!--      <photo title="头像" dir-name="appupload/avatar/" @suc="upsuc" :list="list" :del="false" />-->
    <div class="mt10"></div>
    <nut-form ref="form" size="large" :model-value="form" label-width="80px">
      <nut-form-item label="账号">
        <nut-input v-model="form.username" disabled></nut-input>
        <div class="nut-form-item-msg">账号信息用于登录，系统不允许修改</div>
      </nut-form-item>
      <nut-form-item label="姓名">
        <nut-input v-model="form.name"></nut-input>
      </nut-form-item>
      <nut-form-item label="手机">
        <nut-input v-model="form.mobile"></nut-input>
      </nut-form-item>
      <nut-form-item label="个性签名">
        <nut-input v-model="form.sign" type="textarea"></nut-input>
      </nut-form-item>
    </nut-form>
    <div style="text-align:center;">
      <nut-button class="mt10" type="primary" size="large" style="width: 150px;" @click="save">保存</nut-button>
    </div>
  </div>
</template>

<script>
import tool from "@/utils/tool";
import pinia from '@/stores'
import {useGlobal} from "@/stores/useGlobal";
const global = useGlobal(pinia)
export default {
	// components: {Photo},
	data() {
		return {
			form: {
				id: '',
				username: '',
				name: '',
				mobile: '',
				sex: 0,
				url: ''
			},
			list: [],
			offsetHeight: 170
		}
	},
	mounted () {
		tool.post('user/getUserById', {id: tool.data.getUserId()} ).then(ret => {
			if(ret.stat) {
				let user = ret.data.user
				this.form.id = user.id
				this.form.username = user.username
				this.form.mobile = user.mobile
				this.form.name = user.name
				this.form.sex = user.sex?user.sex:0
				this.form.sign = user.sign
				if(ret.data.avatar) {
					this.list = [{url: ret.data.avatar.url, fileName: ret.data.avatar.fileName}]
				}
			}
		})
	},
	computed: {
    toolbarHei () {
      return global.statusBarHeight
    }
	},
	methods: {
    clickLeft () {
      this.$router.go(-1)
    },
		upsuc (photo) {
			tool.post('user/saveAvatar', {fileName: photo.fileName, id: this.form.id}).then(() => {
				this.list = [{url: photo.url, fileName: photo.fileName}]

			})
		},
		save () {
			tool.post('app/saveUser', {formData: this.form, mod: 'admin'}).then(() => {

			})
		}
	}
}
</script>

<style>
</style>
